home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / dlghlp.exe / DLGHELPX.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1993-05-24  |  3.8 KB  |  137 lines

  1. Program DlgHelpx;
  2.  
  3. { Sample App using a message filter to create context sensitive
  4.   help in a dialog.  This is a very minimal implementation, used
  5.   mainly to demostrate the creation of a Windows hook.  Enhancements
  6.   are left to the imagination of the programmer. }
  7.  
  8. { Written: 7/18/91
  9.          By: Pat Ritchey CIS ID: [70007,4660]
  10.   Changed: 18/05/93
  11.          By: Michael Denzlein CIS ID [100120,2601]}
  12.  
  13. uses WinTypes,WinProcs,OWindows,ODialogs,DlgHelp;
  14.  
  15. {$R DLGHELP.RES}
  16.  
  17. const
  18.     id_Name    =    101;
  19.     id_Address    =    102;
  20.     id_City    =    103;
  21.     id_state    =    104;
  22.     id_zip    =    105;
  23.     cm_Open    =    101;
  24.     cm_Close    =    102;
  25.     cm_Quit    =    103;
  26.     cm_AddCust    =    201;
  27.  
  28.  
  29. {*************************************************************************}
  30. {************************ Filter *****************************************}
  31. {*************************************************************************}
  32.  
  33. Const
  34.   id_Help = 998;
  35.  
  36. {*************************************************************************}
  37. {************************ Dialog *****************************************}
  38. {*************************************************************************}
  39.  
  40. Type
  41.  PHelpDialog = ^THelpDialog;
  42.  THelpDialog = object(TDialog)
  43.     Destructor Done; virtual;
  44.     Procedure SetupWindow; virtual;
  45.     Procedure Help(var Msg : TMessage);
  46.       virtual id_First + id_Help;
  47.     end;
  48.  
  49. Procedure THelpDialog.SetupWindow;
  50. begin
  51.   TDialog.SetupWindow;
  52.   InstallFilter(HWindow, id_Help);
  53. end;
  54.  
  55. Destructor THelpDialog.Done;
  56. begin
  57.  RemoveFilter;
  58.  TDialog.Done;
  59. end;
  60.  
  61. procedure THelpDialog.Help(var Msg: TMessage);
  62. var
  63.   HelpText : Pchar;
  64. { This sample Help method simply uses a message box.  It could
  65.   be modified to call the built in WINHELP facilities }
  66. begin
  67.   { Msg.lParamLo contains the window handle of the window with focus }
  68.   DisableHelp;
  69.   case GetDlgCtrlID(MSg.lParamLo) of
  70.      id_name    : HelpText := 'Enter Customer''s full name';
  71.      id_Address : HelpText := 'Enter Full street address';
  72.      id_City    : HelpText := 'Enter City name';
  73.      id_State   : HelpText := 'Enter State Abbreviation';
  74.      id_Zip     : HelpText := 'Enter 5 or 9 digit Zip code';
  75.      id_OK      : HelpText := 'Press to add customer';
  76.      id_Cancel  : HelpText := 'Press to cancel this entry';
  77.      id_Help        : HelpText := 'Press F1 to get help for a specific field';
  78.      else
  79.         HelpText := 'Unknown Field';
  80.   end;
  81.   MessageBox(hWindow, HelpText, 'Help', mb_Ok);
  82.   EnableHelp;
  83. end;
  84.  
  85. {*************************************************************************}
  86. {************************ Window *****************************************}
  87. {*************************************************************************}
  88.  
  89. type
  90.   PMyWindow = ^TMyWindow;
  91.   TMyWindow = object(TWindow)
  92.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  93.     Procedure CMAddCust(var MSg : TMessage);
  94.       virtual cm_first + cm_AddCust;
  95.     Procedure CMQuit(var Msg : TMEssage);
  96.       virtual cm_first + cm_Quit;
  97.   end;
  98.  
  99. constructor TMyWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  100. begin
  101.   TWindow.Init(AParent, ATitle);
  102.   Attr.Menu := LoadMenu(HInstance,'DLGHELP');
  103. end;
  104.  
  105. Procedure TMyWindow.CMAddCust(Var Msg : TMessage);
  106. begin
  107.   Application^.ExecDialog(New(PHelpDialog,Init(@Self,'DLGHELP')));
  108. end;
  109.  
  110. PRocedure TMyWindow.CMQuit;
  111. begin
  112.   PostQuitMEssage(0);
  113. end;
  114.  
  115. {*************************************************************************}
  116. {************************ Application ************************************}
  117. {*************************************************************************}
  118.  
  119. type
  120.   TMyApplication = object(TApplication)
  121.     procedure InitMainWindow; virtual;
  122.   end;
  123.  
  124. procedure TMyApplication.InitMainWindow;
  125. begin
  126.   MainWindow := New(PMyWindow, Init(nil, 'Sample Help Context'));
  127. end;
  128.  
  129. var
  130.   MyApp : TMyApplication;
  131.  
  132. begin
  133.   MyApp.Init('DLGHELP');
  134.   MyApp.Run;
  135.   MyApp.Done;
  136. end.
  137.